
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>

#include "af.h"

int flag_inet;
int flag_inet6;

char afname[256] = "";


extern struct aftype inet_aftype;
extern struct aftype inet6_aftype;

static short sVafinit = 0;

struct aftype *aftypes[] = {
		&inet_aftype,
#if HAVE_AFINET6
		&inet6_aftype,
#endif
		NULL };

void afinit()
{
	sVafinit = 1;
}


/* Check our protocol family table for this family. */
struct aftype *get_afntype(int af)
{
	struct aftype **afp;

	if (!sVafinit)
		afinit();

	afp = aftypes;
	while (*afp != NULL)
	{
		if ((*afp)->af == af)
			return (*afp);
		afp++;
	}
	return (NULL);
}

/* Check our protocol family table for this family and return its socket */
int get_socket_for_af(int af)
{
	struct aftype **afp;

	if (!sVafinit)
		afinit();

	afp = aftypes;
	while (*afp != NULL)
	{
		if ((*afp)->af == af)
			return (*afp)->fd;
		afp++;
	}
	return -1;
}

